<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="inputData">
        <button @click="addData">提交</button>
        <ul>
            <!-- <li v-for="(item,index) in myData">{{index}} - {{item}}</li> -->
            <todo-item 
                v-bind:content="item" 
                v-for="(item,index) in myData"
                v-bind:index="index"
                @delete="handleSonClick">
            </todo-item>
        </ul>
    </div>
</body>
<script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.js"></script>
<script>
    //全局注册
    // Vue.component("TodoItem",{
    //     props: ['content'],
    //     template:'<li>{{content}}</li>'
    // });
    //部分注册
    var TodoItem = {
        props:['content','index'],
        template:'<li @click="handleSonClick">{{content}}</li>',
        methods:{
            handleSonClick(){
                this.$emit("delete",this.index);
            }
        }
    };
    var app = new Vue({
        el:'#app',
        components:{
            TodoItem:TodoItem
        },
        data(){
            return {
                "myData":[
                    123
                ],
                "inputData":""
            }
        },
        methods:{
            addData(){
                this.myData.push(this.inputData);
                this.inputData = '';
            },
            handleSonClick(index){
                this.myData.splice(index,1);
            }
        }
    })
</script>
</html>